From d1673b3916314521a75e784e7e5d4051f8fed109 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Tue, 13 Apr 2010 12:20:48 +0100 Subject: [PATCH] p2m: merge ptp allocation Signed-off-by: Christoph Egger --- xen/arch/x86/mm/hap/p2m-ept.c | 6 +---- xen/arch/x86/mm/hap/private.h | 3 +-- xen/arch/x86/mm/p2m.c | 45 ++++++++++++++++++++++------------- xen/include/asm-x86/p2m.h | 2 ++ 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/mm/hap/p2m-ept.c b/xen/arch/x86/mm/hap/p2m-ept.c index 45f6285677..1d4fe157c8 100644 --- a/xen/arch/x86/mm/hap/p2m-ept.c +++ b/xen/arch/x86/mm/hap/p2m-ept.c @@ -97,14 +97,10 @@ static int ept_set_middle_entry(struct domain *d, ept_entry_t *ept_entry) { struct page_info *pg; - pg = d->arch.p2m->alloc_page(d); + pg = p2m_alloc_ptp(d, 0); if ( pg == NULL ) return 0; - pg->count_info = 1; - pg->u.inuse.type_info = 1 | PGT_validated; - page_list_add_tail(pg, &d->arch.p2m->pages); - ept_entry->emt = 0; ept_entry->ipat = 0; ept_entry->sp_avail = 0; diff --git a/xen/arch/x86/mm/hap/private.h b/xen/arch/x86/mm/hap/private.h index cb51426f16..e237629376 100644 --- a/xen/arch/x86/mm/hap/private.h +++ b/xen/arch/x86/mm/hap/private.h @@ -30,5 +30,4 @@ unsigned long hap_gva_to_gfn_3_levels(struct vcpu *v, unsigned long gva, unsigned long hap_gva_to_gfn_4_levels(struct vcpu *v, unsigned long gva, uint32_t *pfec); - -#endif /* __SVM_NPT_H__ */ +#endif /* __HAP_PRIVATE_H__ */ diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 53de2cf23b..916fdc2de8 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -134,6 +134,22 @@ p2m_find_entry(void *table, unsigned long *gfn_remainder, return (l1_pgentry_t *)table + index; } +struct page_info * +p2m_alloc_ptp(struct domain *d, unsigned long type) +{ + struct page_info *pg; + + pg = d->arch.p2m->alloc_page(d); + if (pg == NULL) + return NULL; + + page_list_add_tail(pg, &d->arch.p2m->pages); + pg->u.inuse.type_info = type | 1 | PGT_validated; + pg->count_info |= 1; + + return pg; +} + // Walk one level of the P2M table, allocating a new table if required. // Returns 0 on error. // @@ -156,15 +172,14 @@ p2m_next_level(struct domain *d, mfn_t *table_mfn, void **table, /* PoD: Not present doesn't imply empty. */ if ( !l1e_get_flags(*p2m_entry) ) { - struct page_info *pg = d->arch.p2m->alloc_page(d); + struct page_info *pg; + + pg = p2m_alloc_ptp(d, type); if ( pg == NULL ) return 0; - page_list_add_tail(pg, &d->arch.p2m->pages); - pg->u.inuse.type_info = type | 1 | PGT_validated; - pg->count_info |= 1; new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)), - __PAGE_HYPERVISOR|_PAGE_USER); + __PAGE_HYPERVISOR | _PAGE_USER); switch ( type ) { case PGT_l3_page_table: @@ -195,16 +210,15 @@ p2m_next_level(struct domain *d, mfn_t *table_mfn, void **table, if ( type == PGT_l2_page_table && (l1e_get_flags(*p2m_entry) & _PAGE_PSE) ) { unsigned long flags, pfn; - struct page_info *pg = d->arch.p2m->alloc_page(d); + struct page_info *pg; + + pg = p2m_alloc_ptp(d, PGT_l2_page_table); if ( pg == NULL ) return 0; - page_list_add_tail(pg, &d->arch.p2m->pages); - pg->u.inuse.type_info = PGT_l2_page_table | 1 | PGT_validated; - pg->count_info = 1; - + flags = l1e_get_flags(*p2m_entry); pfn = l1e_get_pfn(*p2m_entry); - + l1_entry = map_domain_page(mfn_x(page_to_mfn(pg))); for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ ) { @@ -224,13 +238,12 @@ p2m_next_level(struct domain *d, mfn_t *table_mfn, void **table, if ( type == PGT_l1_page_table && (l1e_get_flags(*p2m_entry) & _PAGE_PSE) ) { unsigned long flags, pfn; - struct page_info *pg = d->arch.p2m->alloc_page(d); + struct page_info *pg; + + pg = p2m_alloc_ptp(d, PGT_l1_page_table); if ( pg == NULL ) return 0; - page_list_add_tail(pg, &d->arch.p2m->pages); - pg->u.inuse.type_info = PGT_l1_page_table | 1 | PGT_validated; - pg->count_info |= 1; - + /* New splintered mappings inherit the flags of the old superpage, * with a little reorganisation for the _PAGE_PSE_PAT bit. */ flags = l1e_get_flags(*p2m_entry); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 0fb485661f..71617f7e92 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -444,6 +444,8 @@ int p2m_mem_paging_prep(struct domain *d, unsigned long gfn); /* Resume normal operation (in case a domain was paused) */ void p2m_mem_paging_resume(struct domain *d); +struct page_info *p2m_alloc_ptp(struct domain *d, unsigned long type); + #endif /* _XEN_P2M_H */ /* -- 2.30.2